package com.fm.openinstall.a;

import com.fm.openinstall.f.*;
import android.os.*;
import android.content.*;

public class b
{
    private static volatile b e;
    Runnable a;
    private c b;
    private ClipboardManager c;
    private Handler d;

    private b(final Context context) {
        this.b = com.fm.openinstall.f.c.a(b.class);
        this.a = new com.fm.openinstall.a.c(this);
        this.c = (ClipboardManager)context.getSystemService("clipboard");
        this.d = new Handler();
    }

    public static b a(final Context context) {
        if (b.e == null) {
            synchronized (b.class) {
                if (b.e == null) {
                    b.e = new b(context);
                }
            }
        }
        return b.e;
    }

    private boolean a(final String s) {
        try {
            final int n = s.indexOf(com.fm.openinstall.f.a.e) + com.fm.openinstall.f.a.e.length();
            return System.currentTimeMillis() < Long.parseLong(s.substring(n, s.indexOf("-", n)));
        }
        catch (Exception ex) {
            return true;
        }
    }

    public com.fm.openinstall.b.a a(final String s, final String s2) {
        final com.fm.openinstall.b.a a = new com.fm.openinstall.b.a();
        if (s != null && s.contains(com.fm.openinstall.f.a.d)) {
            a.b(s);
            a.b(2);
        }
        if (s2 != null && com.fm.openinstall.f.e.b(s2).contains(com.fm.openinstall.f.a.d)) {
            a.a(s2);
            a.b(1);
        }
        return a;
    }

    public boolean a() {
        final ClipData primaryClip = this.c.getPrimaryClip();
        if (primaryClip != null && primaryClip.getItemCount() > 0) {
            final ClipData.Item item = primaryClip.getItemAt(0);
            if (item != null) {
                final int sdk_INT = Build.VERSION.SDK_INT;
                String string = null;
                String htmlText;
                if (sdk_INT >= 16) {
                    htmlText = item.getHtmlText();
                }
                else {
                    htmlText = null;
                }
                if (item.getText() != null) {
                    string = item.getText().toString();
                }
                if (htmlText != null && htmlText.contains(com.fm.openinstall.f.a.e)) {
                    if (this.a(htmlText)) {
                        return true;
                    }
                    this.c();
                }
                if (string != null) {
                    final String b = com.fm.openinstall.f.e.b(string);
                    if (b.contains(com.fm.openinstall.f.a.e)) {
                        if (this.a(b)) {
                            return true;
                        }
                        this.c();
                    }
                }
            }
        }
        return false;
    }

    public com.fm.openinstall.b.a b() {
        final com.fm.openinstall.b.a a = new com.fm.openinstall.b.a();
        final ClipData primaryClip = this.c.getPrimaryClip();
        com.fm.openinstall.b.a a2 = a;
        if (primaryClip != null) {
            a2 = a;
            if (primaryClip.getItemCount() > 0) {
                final ClipData.Item item = primaryClip.getItemAt(0);
                a2 = a;
                if (item != null) {
                    final int sdk_INT = Build.VERSION.SDK_INT;
                    String string = null;
                    String htmlText;
                    if (sdk_INT >= 16) {
                        htmlText = item.getHtmlText();
                    }
                    else {
                        htmlText = null;
                    }
                    if (item.getText() != null) {
                        string = item.getText().toString();
                    }
                    a2 = this.a(htmlText, string);
                }
            }
        }
        return a2;
    }

    public void c() {
        this.d.postDelayed(this.a, 2000L);
    }
}
